//
//  ActivityTableViewController.m
//  EarnCommision
//
//  Created by Nancy on 3/13/15.
//  Copyright (c) 2015 EC. All rights reserved.
//

#import "ActivityTableViewController.h"
#import "UIViewExt.h"

#define kScreenHeight [UIScreen mainScreen].bounds.size.height
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
@interface ActivityTableViewController ()

@property (strong,nonatomic) NSArray *activityArr;
@end

@implementation ActivityTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    /*NSString *fullpath=[[NSBundle mainBundle]pathForResource:@"activity.plist" ofType:nil];
    NSArray *temparray=[NSArray arrayWithContentsOfFile:fullpath];
    NSMutableArray *arrayM=[NSMutableArray arrayWithCapacity:temparray.count];
    for (NSDictionary *dict in temparray) {
        [arrayM addObject:dict];
    }
    _activityArr=[arrayM mutableCopy];*/
    
    //[self.view setBackgroundColor:[UIColor colorWithRed:100 green:100 blue:100 alpha:0.5]];
    
   // [self.view setBackgroundColor:[UIColor redColor]];
   
    
    m_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0 , kScreenWidth, kScreenHeight)];
    [m_tableView setBackgroundColor:[UIColor clearColor]];
    [m_tableView setDelegate:self];
    [m_tableView setDataSource:self];
    m_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:m_tableView];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 4;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    
    ActivityCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[ActivityCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
  //  NSDictionary * dataDic = [_activityArr objectAtIndex:indexPath.row];
   // cell.m_titleLabel.text = [dataDic valueForKey:@"text"];
    cell.m_titleLabel.text = @"title";
    cell.backgroundColor = [UIColor redColor];
    UIImage *image = [UIImage imageNamed:@"latest_activities_image_1.png"];
    [cell setImageView:image];
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 155;
}

@end

@implementation ActivityCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    float scale = kScreenWidth/320.0;
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //self.backgroundColor = [UIColor colorWithRed:100 green:100 blue:100 alpha:.5];
        
        float bHeight = (kScreenWidth-30)/290.0*115+30;
        float imgScale = (kScreenWidth-30)/290.0;
        _m_cellBackground = [[UIView alloc]initWithFrame:CGRectMake(10, 10, kScreenWidth-20, bHeight)];
        [_m_cellBackground setBackgroundColor:[UIColor whiteColor]];
        _m_imageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 10, _m_cellBackground.width-10, 115*imgScale)];
        [_m_cellBackground addSubview:_m_imageView];

        _m_titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, _m_imageView.bottom, _m_cellBackground.width-20, 20)];
        [_m_titleLabel setBackgroundColor:[UIColor clearColor]];
        [_m_cellBackground addSubview:_m_titleLabel];
        
        
        [self addSubview:_m_cellBackground];
        self.selectionStyle = UITableViewCellSelectionStyleGray;
    }
    return self;
}

- (void)setImageView:(UIImage*)image
{
    _m_imageView.image = image;
    float scale = kScreenWidth/320.0;
    [_m_imageView setFrame:CGRectMake(5, 10, 290*scale, 115*scale)];
}

@end
